<template>
    <rx-dialog style="height: 100%;" @handOk="onOk" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <a-form  layout="horizontal" class="rx-a-form-vertical">
                    <a-form-item  :label="i18n('formTran','单据转换')">
                        <rx-input-button v-model="dialogVal"
                                         @click="selectFormTranConfig"
                        >
                        </rx-input-button>
                    </a-form-item>
                    <a-form-item  :label="i18n('formSource','源单来源')">
                        <a-radio-group v-model="formTranConfig.formSource"
                                       :options="formSourceArr"
                        >
                        </a-radio-group>
                    </a-form-item>
                    <template v-if="formTranConfig.formSource=='searchView'">
                        <a-form-item  :label="i18n('searchView','选择系统视图')">
                            <rx-input-button v-model="searchViewdialogVal"
                                             @click="selectSearchViewConfig"
                            >
                            </rx-input-button>
                        </a-form-item>
                    </template>

                    <a-form-item  :label="i18n('tranType','单据转换选项')">
                        <a-radio-group v-model="formTranConfig.tranType"
                                       :options="tranTypeArr"
                        >
                        </a-radio-group>
                    </a-form-item>
                    <template v-if="formTranConfig.tranType=='open'">
                        <a-form-item  :label="i18n('readonly','是否只读')">
                            <a-radio-group v-model="formTranConfig.readonly"
                                           :options="readonlyArr"
                            >
                            </a-radio-group>
                        </a-form-item>
                        <a-form-item :label="i18n('callbackmethod','回调方法')" >
                            <a-input :placeholder="i18n('callMethodDesc','请输入回调函数名称,参数为')+ '(action,data)'" v-model="formTranConfig.callbackMethod" style='width: 300px;' />
                        </a-form-item>

                        <a-form-item :label="i18n('dialogSize','弹框大小')" >
                            <div style="display: flex;align-items: center;white-space: nowrap;">
                                <div style="height: 40px;display: flex;align-items: center;">
                                    <a-radio-group v-model="formTranConfig.isMax"  :options="sizeOptions"></a-radio-group>
                                </div>
                                <template v-if="formTranConfig.isMax=='NO'">
                                    <span >{{i18n('width','宽')}}：</span>
                                    <div style="padding:0 10px;width: 100px;">
                                        <a-input-number v-model="formTranConfig.width"></a-input-number>
                                    </div>
                                    <span>{{i18n('height','高')}}：</span>
                                    <div style="padding:0 10px;width: 100px;">
                                        <a-input-number v-model="formTranConfig.height"></a-input-number>
                                    </div>
                                </template>
                            </div>
                        </a-form-item>
                    </template>
                </a-form>
            </div>
        </rx-layout>
    </rx-dialog>
</template>

<script>
import {RxDialog, Util,FormBoListPreview,PublicFunction,GridMixin} from "@lowcode/jpaas-common-lib";
import DialogBox from "@/assets/js/DialogBox";
export default {
    name: "FormBoListConfigFormTranDialog",
    props: {
        layerid: {
            type: String,
            default: ""
        },
        destroy: {
            type: Function
        },
        pkId:{
            type: String,
            default: ""
        },
        /**
         * 业务模型ID
         */
        boDefId:{
            type: String,
            default: ""
        },
        formTranConfigStr:{
            type: String
        },
    },
    data(){
        return {
            dialogVal:"",
            searchViewdialogVal:"",
            readonlyArr:[
                {value: true, label: this.i18n('yes','是')},
                {value: false, label: this.i18n('no','否')},
            ],
            formSourceArr:[
                {value: "selectRow", label: this.i18n('formSourceOpt.selectRow',"选中行")},
                {value: "queryData", label: this.i18n('formSourceOpt.queryData',"查询结果")},
                {value: "searchView", label: this.i18n('formSourceOpt.searchView',"系统视图")},
            ],
            tranTypeArr:[
                {value: "open", label: this.i18n('tranTypeOpt.open','打开表单')},
                {value: "save", label: this.i18n('tranTypeOpt.save','保存')},
            ],
            sizeOptions:[
                {label:this.i18n('sizeOpt.full','全屏'),value:"YES"},
                {label:this.i18n('sizeOpt.custom','自定义'),value:"NO"}
            ],
            formTranConfig: {
                pkId:"",
                listId: this.pkId,
                formTranName:"",//单据转换名称
                formTranId:"",//单据转换主键
                searchViewName:"",
                searchViewId:"",
                tranCount: 10,//系统视图状态下需要转换的数量
                formSource:"selectRow",//源单来源
                tranType:"open",//单据转换选项
                //回调方法
                callbackMethod:'',
                //是否只读
                readonly:false,
                isMax:"YES",
                height:600,
                width:800

            },
        }
    },
    created(){
        let formTranConfig = {};
        if(this.formTranConfigStr){
            formTranConfig = JSON.parse(this.formTranConfigStr);
            //合并对象
            Object.assign(this.formTranConfig,formTranConfig);
            this.dialogVal = {text:this.formTranConfig.formTranName,value:this.formTranConfig.formTranId}
            this.searchViewdialogVal = {text:this.formTranConfig.searchViewName,value:this.formTranConfig.searchViewId}
        }
    },
    methods:{
        i18n(name,text,key){
            return this.$ti18(name,text,"formTransConfig.listConfigDialog",key);
        },
        selectFormTranConfig() {
            if (!this.boDefId){
                this.$message.error(this.i18n('selectDef','请选择表单方案'))
                return;
            }
            let confSol = {
                curVm: this,
                widthHeight: ['1000px', '600px'],
                data: {boDefId : this.boDefId}
            };
            let self_ = this;
            DialogBox.openFormTran(confSol, function (data) {
                if (data){
                    self_.dialogVal=JSON.stringify({text:data[0].name,value:data[0].pkId})
                    self_.formTranConfig.formTranId=data[0].pkId
                    self_.formTranConfig.formTranName=data[0].name
                }
            })
        },
        selectSearchViewConfig() {
            let confSol = {
                curVm: this,
                widthHeight: ['800px', '500px'],
                data: {listId : this.pkId}
            };
            let self_ = this;
            DialogBox.openSearchView(confSol, function (data) {
                debugger
                if (data){
                    self_.searchViewdialogVal=JSON.stringify({text:data[0].name,value:data[0].pkId})
                    self_.formTranConfig.searchViewId=data[0].pkId
                    self_.formTranConfig.searchViewName=data[0].name
                }
            })
        },
        onOk(){
            Util.closeWindow(this,"ok",this.formTranConfig);
        },
        cancel(){
            Util.closeWindow(this,"cancel");
        },
    }
}
</script>

<style scoped>

</style>